<template>
     <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
        <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
            :immediate-check="false"
        >
            <slot></slot>
        </van-list>
     </van-pull-refresh>
</template>


<script>

export default {
    data(){
        return {
            isLoading:false,
            loading:false,
            finished:false //数据是否全部请求到了
        }
    },
    props:{
       refresh:Function, //刷新
       loaddata:Function, //加载更多
    },
    methods:{
        onRefresh(){
            this.isLoading = true; //正在刷新
            this.refresh(()=>{
                this.isLoading = false;
                this.$toast("刷新成功")
            })
        },
        //请求跟多数据
        onLoad(){
            this.loaddata(()=>{
                this.finished = true;
                this.$toast("数据到底啦")
            },()=>{
                this.loading = false;
                this.$toast("加载成功")
            })
        }
    }
}
</script>